<template>


  <Row style="padding: 10px;">
    <database_table
      :column_header="column_header"
      :table_data="table_data"
      :total_page="total_page"></database_table>

  </Row>
</template>
<script>
  import database_table from '../utils/table_components_util'

  export default {
    data() {
      return {
        column_header: [
          {
            title: '表名',
            key: 'name',
            align: 'left',
            sortable: true,
            width: 250
          },
          {
            title: "数据类型",
            key: "datatype",
            align: 'center',
            width: 150
          },
          {
            title: "长度",
            key: "length",
            align: 'center',
            width: 100
          },
          {
            title: "是否允许为空",
            key: "nullable",
            align: 'center',
            width: 100
          },
          {
            title: '说明',
            key: 'comment',
            align: 'left'
          },
          {
            title: '详情',
            key: 'handler',
            align: 'center',
            width: 200,
            render: (h, params) => {
              return h('div', [
                h('span', {
                  on: {
                    click: () => {
                      this.$emit('childClickMenu', '系统管理', '代码生成', 'code_list', {"id": params.row.id});
                    }
                  }
                }, "增加到编辑"),
                h('span', {
                  on: {
                    click: () => {
                      this.$emit('childClickMenu', '系统管理', '代码生成', 'code_list', {"id": params.row.id});
                    }
                  }
                }, "增加到查询")
              ]);
            }
          }
        ],
        table_data: []
      }
    },
    components: {
      database_table: database_table
    },
    created: function () {
      //加载表格数据
      this.loadTableData();
    },
    methods: {
      /**
       * 加载表格数据
       * @param page_num            查询条件：当前页
       */
      loadTableData: function () {
        this.$http.post(this.apiUrl() + "code/columns/grid/", {
          current_page: this.current_page,
          table_name: this.params.table_name
        }, {
          emulateJSON: true
        }).then((response) => {
          if (response.body.success) {
            this.table_data = response.body.grid;
          }
        });
      }
    },
    props: ['params']
  }
</script>
<style scoped>
  .page_class {
    float: right;
    padding-top: 10px;
    padding-bottom: 10px;
  }
</style>
